package leetcode.hot100;

import java.util.Arrays;

public class Solution238 {

    public static void main(String[] args) {

        int[] nums = {1,2,3,4};
        int[] res = new Solution238().productExceptSelf(nums);
        System.out.println();

    }

    public int[] productExceptSelf(int[] nums) {
        int[] res = new int[nums.length];
        Arrays.fill(res,1);

        for (int i=1;i<nums.length;i++){
            res[i] = res[i-1]*nums[i-1];
        }

        int tmp = 1;
        for (int i = nums.length-1; i >=0 ; i--) {
            res[i] *= tmp;
            tmp *= nums[i];
        }

        return res;
    }
}
